﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Org.BouncyCastle.Utilities.Encoders;

namespace Bitcoin.Test.TestData
{
    class Base58KeysValidPublicData : IEnumerable<TestCaseData>
    {
        public IEnumerator<TestCaseData> GetEnumerator()
        {
            var file = "TestData\\base58_keys_valid.json";
            JArray json;
            using (var tr = new StreamReader(file))
            {
                json = JArray.Parse(tr.ReadToEnd());
            }
            foreach (JArray data in json)
            {
                var base58 = (string) data[0];
                var hex = (string) data[1];
                var bytes = Hex.Decode(hex);
                var flags = (JObject) data[2];
                var addressType = (string) flags["addrType"];
                var isPrivateKey = (bool) flags["isPrivkey"];
                var isTestNet = (bool) flags["isTestnet"];
                if (!isPrivateKey)
                {
                    // TODO: Script addresses not supported yet.
                    if (addressType == "pubkey")
                    {
                        yield return new TestCaseData(base58, bytes, addressType, isTestNet);
                    }
                }
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
